package com.train.daily.facade.admin;

import cn.hutool.core.bean.BeanUtil;
import com.train.common.group.EditGroup;
import com.train.common.resp.CommonResp;
import com.train.common.resp.PageResp;
import com.train.daily.dto.token.DailyTrainSkTokenEditDTO;
import com.train.daily.dto.token.DailyTrainSkTokenPageDTO;
import com.train.daily.req.token.DailyTrainSkTokenEditReq;
import com.train.daily.req.token.DailyTrainSkTokenPageReq;
import com.train.daily.resp.token.DailyTrainSkTokenPageResp;
import com.train.daily.service.DailyTrainSkTokenService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * dailyTrainSkToken Facade 接口
 * @author baitiaojun
 * @createDate 2025-03-20 00:19:41
 */
@RequestMapping("/admin/sk-token")
@RestController("adminDailyTrainSkTokenFacade")
@Slf4j
@RequiredArgsConstructor
public class DailyTrainSkTokenFacade {

    private final DailyTrainSkTokenService dailyTrainSkTokenService;

    @PostMapping("page")
    public CommonResp pageList(@RequestBody @Validated DailyTrainSkTokenPageReq req) {
        DailyTrainSkTokenPageDTO dailyTrainSkTokenPageDTO = BeanUtil.copyProperties(req, DailyTrainSkTokenPageDTO.class);
        PageResp<DailyTrainSkTokenPageResp> pageResp = dailyTrainSkTokenService.pageList(dailyTrainSkTokenPageDTO);
        return CommonResp.ok(pageResp);
    }

    @PostMapping("edit")
    public CommonResp edit(@RequestBody @Validated(EditGroup.class) DailyTrainSkTokenEditReq req) {
        DailyTrainSkTokenEditDTO dailyTrainSkTokenEditDTO = BeanUtil.copyProperties(req, DailyTrainSkTokenEditDTO.class);
        dailyTrainSkTokenService.editDailyTrainSkToken(dailyTrainSkTokenEditDTO);
        return CommonResp.ok();
    }

    @DeleteMapping("remove/{id}")
    public CommonResp delete(@PathVariable("id") Long id) {
        dailyTrainSkTokenService.remove(id);
        return CommonResp.ok();
    }
}
